package com.life.muyu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.life.muyu.model.News;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface NewsMapper extends BaseMapper<News> {
//    @Select("select * from t_news ")
//    List<News> selectAllNews();

    @Select("select * from t_news limit #{param1},#{param2} ")
    List<News> selectNewsWithLimitSize(Integer offset,Integer pageSize);

    @Select("select * from t_news where id = #{param1}")
    News selectNewsById(Integer id);

    @Insert("insert into t_news values(null,#{cover},#{description},#{newsDate},#{newsHref},#{newsTitle})")
    void insertNews(News news);

    @Update("update t_news set " +
            "t_news.cover=#{cover},"+
            "t_news.description=#{description}," +
            "t_news.news_date=#{newsDate}," +
            "t_news.news_href=#{newsHref}," +
            "t_news.news_title=#{newsTitle}  where id = #{id}")
    void updateNews(News news);

    @Update("update t_news set " +
            "t_news.description=#{description}," +
            "t_news.news_date=#{newsDate}," +
            "t_news.news_href=#{newsHref}," +
            "t_news.news_title=#{newsTitle} where id = #{id}")
    void updateNewsWithoutCover(News news);

    void deleteNewsByIds(int[] ids);
}
